Kademi uses a templating system which allows you to completely change the behaviour of any page in your website, and to create new templates with dynamic capabilities.
For example, you can create a template that renders a product, and use custom fields to store structured content. The template could dynamically display orders of the product by the current customer and related products, etc.
Template code is executed using Apache Velocity template engine.
Template structure
Kademi uses a three level structure of content and templates:
- The page itself, ie a html page or an app provided resource. Example of this page - make sure you view source!
- The page template, which controls the content layout for a specific type of content or resource
- The theme template, which controls the layout common to all pages such as menu, footer, etc
- The raw HTML for this page - example raw page - (make sure you view source)
- The page template for this page - example page template - (make sure you view source)
- Example theme template, used by this page - example theme template - (make sure you view source)
By default any html page will be rendered in a template. If no template is specified the default page template will be used.
To prevent templating insert a DOCTYPE declaration at the top of the html:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns='http://www.w3.org/1999/xhtml'> <head> ...
To specify a template (either for a page or for a page template) use a link element like this:
<link rel="template" href="/ref/guides/theme/howtoPage" />
Template Rendering
When a page is rendered by the templating system, the system first locates its page template and theme template. It collects header elements (eg js and css files) into a single list, and css references are merged to allow LESS compilation and then executes the body templates.
The theme template is executed first. The content in its body tag is used as a template and the content tag is used to output content inside the template:
#content
The content tag passes execution to the page template, which also has its body executed as a template. For application provided resources (eg dashboard and profile pages) there is no underlying html page, and the page template is executed using objects in context such as the current user. For HTML pages, the page template uses the body and title from the html file to output the actual content of the page:
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <link rel="stylesheet" type="text/css" href="/theme/javadoc.css" title="Style" /> </head> <body> <div class="container"> <h1>$page.title</h1> <div class="content"> $!body </div> </div> </body> </html>
Template Variables
Several variables are placed in the rendering context for use by templates
Name | Type | Description |
request | Request | The request object, which allows access to request variables, cookies, etc |
page | Depends on the resource being accessed | This represents the current resource being accessed. Eg a BlogArticleFolder, a ProfilePage, DashboardPage, etc |
rootFolder | WebsiteRootFolder, or OrganisationFolder for admin pages | The root resource for the current host/domain |
folder | The parent resource of the currently accessed resource | |
params | Map | Request parameters, as a map of keys and values |
user | UserResource | The current user, expressed as a resource |
profile | ExtProfileBean | The current user, expressed as a light weight object |
userResource | UserResource (alias for user) | |
applicationManager | ApplicationManager | |
applications | Applications | |
menu | MenuItem | The root menu item for this site |
formatter | Formatter | Lots of useful methods for formatting and parsing data |
Programming with Kademi Forms
Ask a question, or offer an answer